package com.xjrsoft.module.customerTwo.barin.t_enterprise_archives_info.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xjrsoft.common.page.PageOutput;
import com.xjrsoft.common.page.ConventPage;
import java.util.List;
import com.xjrsoft.common.result.Response;
import com.xjrsoft.core.tool.utils.BeanUtil;
import com.xjrsoft.module.customerTwo.barin.t_enterprise_archives_info.dto.TEnterpriseArchivesInfoDto;
import com.xjrsoft.module.customerTwo.barin.t_enterprise_archives_info.dto.SaveTEnterpriseArchivesInfoFormDataDto;
import com.xjrsoft.module.customerTwo.barin.t_enterprise_archives_info.vo.TEnterpriseArchivesInfoFormDataVo;
import com.xjrsoft.module.customerTwo.barin.t_enterprise_archives_info.vo.TEnterpriseArchivesInfoListVo;
import com.xjrsoft.module.customerTwo.barin.t_enterprise_archives_info.dto.TEnterpriseArchivesInfoListDto;
import com.xjrsoft.module.customerTwo.barin.t_enterprise_archives_info.vo.TEnterpriseArchivesAnnualReportVo;
import com.xjrsoft.module.customerTwo.barin.t_enterprise_archives_info.entity.TEnterpriseArchivesAnnualReport;
import com.xjrsoft.module.customerTwo.barin.t_enterprise_archives_info.dto.TEnterpriseArchivesAnnualReportDto;
import com.xjrsoft.module.customerTwo.barin.t_enterprise_archives_info.vo.TEnterpriseArchivesProductVo;
import com.xjrsoft.module.customerTwo.barin.t_enterprise_archives_info.entity.TEnterpriseArchivesProduct;
import com.xjrsoft.module.customerTwo.barin.t_enterprise_archives_info.dto.TEnterpriseArchivesProductDto;
import com.xjrsoft.core.secure.utils.SecureUtil;
import com.xjrsoft.core.tool.utils.FlowableUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;

import org.springframework.web.bind.annotation.*;
import com.xjrsoft.module.customerTwo.barin.t_enterprise_archives_info.entity.TEnterpriseArchivesInfo;
import com.xjrsoft.module.customerTwo.barin.t_enterprise_archives_info.vo.TEnterpriseArchivesInfoVo;
import com.xjrsoft.module.customerTwo.barin.t_enterprise_archives_info.service.ITEnterpriseArchivesInfoService;

/**
 *  控制器
 *
 * @author dongxinhang
 * @since 2025-05-28
 */
@RestController
@AllArgsConstructor
@RequestMapping("/t_enterprise_archives_info")
@Api(value = "企业档案信息", tags = "企业档案信息接口")
public class TEnterpriseArchivesInfoController {


	private final ITEnterpriseArchivesInfoService tEnterpriseArchivesInfoService;


	/**
	 * 详情 
	 */
	@GetMapping("/{id}")
	@ApiOperation(value = "详情", notes = "传入tEnterpriseArchivesInfo")
	@SaCheckPermission(value = {"t_enterprise_archives_info:view", "t_enterprise_archives_info:modify"}, mode = SaMode.OR)
	public Response<TEnterpriseArchivesInfoFormDataVo> getFormData(@PathVariable String id) {
		TEnterpriseArchivesInfoFormDataVo formDataVo = new TEnterpriseArchivesInfoFormDataVo();
		// 主表数据
		TEnterpriseArchivesInfo tEnterpriseArchivesInfo = tEnterpriseArchivesInfoService.getById(id);
		TEnterpriseArchivesInfoVo tEnterpriseArchivesInfoVo = BeanUtil.copy(tEnterpriseArchivesInfo, TEnterpriseArchivesInfoVo.class);
		formDataVo.setTEnterpriseArchivesInfoVo(tEnterpriseArchivesInfoVo);
		// 从表数据
		List<TEnterpriseArchivesAnnualReportVo> tEnterpriseArchivesAnnualReportVoList = BeanUtil.copyList(tEnterpriseArchivesInfoService.getTEnterpriseArchivesAnnualReportByParentId(id), TEnterpriseArchivesAnnualReportVo.class);
		formDataVo.setTEnterpriseArchivesAnnualReportVoList(tEnterpriseArchivesAnnualReportVoList);
		List<TEnterpriseArchivesProductVo> tEnterpriseArchivesProductVoList = BeanUtil.copyList(tEnterpriseArchivesInfoService.getTEnterpriseArchivesProductByParentId(id), TEnterpriseArchivesProductVo.class);
		formDataVo.setTEnterpriseArchivesProductVoList(tEnterpriseArchivesProductVoList);
		return Response.ok(formDataVo);
	}

	/**
	 * 自定义分页 
	 */
	@GetMapping
	@ApiOperation(value = "分页", notes = "传入tEnterpriseArchivesInfo")
		public Response<PageOutput<TEnterpriseArchivesInfoListVo>> getPageList(TEnterpriseArchivesInfoListDto listDto) {
		IPage<TEnterpriseArchivesInfo> page = tEnterpriseArchivesInfoService.getPageList(listDto);
		List<TEnterpriseArchivesInfoListVo> records = BeanUtil.copyList(page.getRecords(), TEnterpriseArchivesInfoListVo.class);
			// 工作流数据处理
		FlowableUtil.systemFormList(records, SecureUtil.getModuleId());
		return Response.ok(ConventPage.getPageOutput(page.getTotal(), records));
	}

	/**
	 * 新增 
	 */
	@PostMapping
	@ApiOperation(value = "新增", notes = "传入tEnterpriseArchivesInfo")
	@SaCheckPermission("t_enterprise_archives_info:add")
	public Response save(@RequestBody SaveTEnterpriseArchivesInfoFormDataDto formDto) {
		TEnterpriseArchivesInfoDto tEnterpriseArchivesInfoDto = formDto.getTEnterpriseArchivesInfoDto();
		TEnterpriseArchivesInfo tEnterpriseArchivesInfo = BeanUtil.copy(tEnterpriseArchivesInfoDto, TEnterpriseArchivesInfo.class);
		List<TEnterpriseArchivesAnnualReportDto> tEnterpriseArchivesAnnualReportDtoList = formDto.getTEnterpriseArchivesAnnualReportDto();
		List<TEnterpriseArchivesAnnualReport> tEnterpriseArchivesAnnualReportList = BeanUtil.copyList(tEnterpriseArchivesAnnualReportDtoList, TEnterpriseArchivesAnnualReport.class);
		List<TEnterpriseArchivesProductDto> tEnterpriseArchivesProductDtoList = formDto.getTEnterpriseArchivesProductDto();
		List<TEnterpriseArchivesProduct> tEnterpriseArchivesProductList = BeanUtil.copyList(tEnterpriseArchivesProductDtoList, TEnterpriseArchivesProduct.class);
		String dataId = tEnterpriseArchivesInfoService.addTEnterpriseArchivesInfo(tEnterpriseArchivesInfo, tEnterpriseArchivesAnnualReportList, tEnterpriseArchivesProductList);
		return dataId == null ? Response.notOk() : Response.ok(dataId);
	}

	/**
	 * 修改 
	 */
	@PutMapping("/{id}")
	@ApiOperation(value = "修改", notes = "传入tEnterpriseArchivesInfo")
	@SaCheckPermission("t_enterprise_archives_info:modify")
	public Response update(@PathVariable String id, @RequestBody SaveTEnterpriseArchivesInfoFormDataDto formDto) {
		TEnterpriseArchivesInfoDto tEnterpriseArchivesInfoDto = formDto.getTEnterpriseArchivesInfoDto();
		TEnterpriseArchivesInfo tEnterpriseArchivesInfo = BeanUtil.copy(tEnterpriseArchivesInfoDto, TEnterpriseArchivesInfo.class);

		List<TEnterpriseArchivesAnnualReportDto> tEnterpriseArchivesAnnualReportDtoList = formDto.getTEnterpriseArchivesAnnualReportDto();
		List<TEnterpriseArchivesAnnualReport> tEnterpriseArchivesAnnualReportList = BeanUtil.copyList(tEnterpriseArchivesAnnualReportDtoList, TEnterpriseArchivesAnnualReport.class);

		List<TEnterpriseArchivesProductDto> tEnterpriseArchivesProductDtoList = formDto.getTEnterpriseArchivesProductDto();
		List<TEnterpriseArchivesProduct> tEnterpriseArchivesProductList = BeanUtil.copyList(tEnterpriseArchivesProductDtoList, TEnterpriseArchivesProduct.class);
		return Response.status(tEnterpriseArchivesInfoService.updateTEnterpriseArchivesInfo(id, tEnterpriseArchivesInfo, tEnterpriseArchivesAnnualReportList, tEnterpriseArchivesProductList));
	}



	/**
	 * 删除 
	 */
	@DeleteMapping("/{ids}")
	@ApiOperation(value = "删除", notes = "传入ids")
	@SaCheckPermission(value = {"t_enterprise_archives_info:batchDelete", "t_enterprise_archives_info:delete"}, mode = SaMode.OR)
	public Response remove(@ApiParam(value = "主键集合", required = true) @PathVariable String ids) {
		return Response.status(tEnterpriseArchivesInfoService.delete(ids));
	}


}
